[12.x] Improved algorithm for Number::pairs() #52641
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
A short while ago I submitted a PR for a new
Number
macro calledpairs()
. However, while using it in a production app I realized that it didn't perform exactly how I intended because it was missing an important argument: the starting value.This PR introduces a new
$start
argument, which improves the behavior of the method to match expectations. Before, the$offset
argument was being reused for both but this was conflating things and resulted in weird offsets. With a distinct$start
argument both the initial value and the increment between pairs can be individually controlled.Note: This is a breaking change due to a new 3rd argument!
Before
While this looks fine, you'll notice that you can't get the values to end in 999, ie.
[1, 999]
or[0, 999]
. This means that your offset/pagination value must always start with1
, which may be incorrect.After
Now, starting value and offsets are distinct allowing for the proper pairing.